package org.csu.logistics.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.logistics.common.CommonResponse;
import org.csu.logistics.entity.TransCenter;
import org.csu.logistics.entity.Warehouse;
import org.csu.logistics.persistence.TransCenterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("TransCenterService")
public class TransCenterServiceImp implements TransCenterService{
    @Autowired
    TransCenterMapper transCenterMapper;

    @Override
    public int insert_transCenter(TransCenter transCenter) {
        return transCenterMapper.insert(transCenter);
    }

    @Override
    public void delete_transCenterByWarehouseId(int warehouseId) {
        QueryWrapper<TransCenter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("warehouseid",warehouseId);
        transCenterMapper.delete(queryWrapper);
    }

    @Override
    public void update_transCenterByWarehouseId(TransCenter transCenter) {
        QueryWrapper<TransCenter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("warehouseid",transCenter.getWarehouseId());
        transCenterMapper.update(transCenter,queryWrapper);
    }

    @Override
    public TransCenter select_transCenterByWareHouseId(int warehouseId) {
        QueryWrapper<TransCenter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("warehouseid",warehouseId);
        TransCenter transCenter = transCenterMapper.selectOne(queryWrapper);
        if(transCenter==null){
            return null;
        }
        return transCenter;
    }

    @Override
    public TransCenter select_transCenterByLocale(String locale) {
        QueryWrapper<TransCenter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("locale",locale);
        TransCenter transCenter = transCenterMapper.selectOne(queryWrapper);
        if(transCenter==null){
            return null;
        }
        return transCenter;
    }

    @Override
    public List<TransCenter> select_transCenterList(){
        return transCenterMapper.selectList(null);
    }
}
